﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using TerraExplorerX;
using TK3DSim.Other;

namespace Tpro6Container.Class.ObjectClass
{
    public  class TankClass: ArmyObject
    {
        public TerraExplorerX.ITerrainModel6 tmodel;
        private TerraExplorerX.ITerrainImageLabel6 img;
        private TerraExplorerX.ITerrainImageLabel6 img1;
        public TankClass(TerraExplorerX.IPosition6 point,string modelname,double modlescal,string imgshowname,
            double imgscal, double showimgx, double showimgy, double showimgz, string targtename, double imgtargtescal)
        {
            //this.point = point;
            double x = point.X;
            double y = point.Y;
            int id = GlobalObjects.Instance.World3D.ProjectTree.FindItem("装备");
            tmodel = GlobalObjects.Instance.World3D.Creator.CreateModel(point, Application.StartupPath + @"\Model" + modelname, modlescal, TerraExplorerX.ModelTypeCode.MT_ANIMATION, id, "坦克");

            img = GlobalObjects.Instance.World3D.Creator.CreateImageLabel(point, Application.StartupPath + @"\Model" + imgshowname, null, id, "");
            img1 = GlobalObjects.Instance.World3D.Creator.CreateImageLabel(point, Application.StartupPath + @"\Model" + targtename, null, id, "");
            img.Style.Scale = imgscal;
            img1.Style.Scale = imgtargtescal;
            img.Attachment.AttachTo(tmodel.ID, showimgx, showimgy, showimgz);
            GlobalObjects.Instance.World3D.ProjectTree.SetVisibility(img1.TreeItem.ItemID,false);

        }

        public TankClass(TerraExplorerX.IPosition6 point, TerraExplorerX.IPosition6 pointt, double seepd,string modelname, double modlescal, string imgshowname,
            double imgscal, double showimgx, double showimgy, double showimgz, string targtename, double imgtargtescal)
        {
            //this.point = point;
            double x = point.X;
            double y = point.Y;
            int id = GlobalObjects.Instance.World3D.ProjectTree.FindItem("装备");

            double[] vv = new double[] {

                        point.X,  point.Y,  0, 
            
                        pointt.X,  pointt.Y,  0};


            ITerrainDynamicObject6 pdyna = GlobalObjects.Instance.World3D.Creator.CreateDynamicObject(vv, TerraExplorerX.DynamicMotionStyle.MOTION_GROUND_VEHICLE, TerraExplorerX.DynamicObjectType.DYNAMIC_VIRTUAL, "路径", 1, TerraExplorerX.AltitudeTypeCode.ATC_ON_TERRAIN, id, "");
            //IRouteWaypoint6

            pdyna.Waypoints.AddWaypoint(GlobalObjects.Instance.World3D.Creator.CreateRouteWaypoint( pointt.X,  pointt.Y,0, seepd,90,0,0,0,0,""));
            pdyna.Waypoints.AddWaypoint(GlobalObjects.Instance.World3D.Creator.CreateRouteWaypoint( point.X,  point.Y,0, seepd,90,0,0,0,0,""));
            //pdyna.
            
            //for (int i = 0; i < pdyna.Waypoints.Count; i++)
            //{
            //    pdyna.Waypoints.GetWaypoint(i).Speed = seepd;
            //}


            tmodel = GlobalObjects.Instance.World3D.Creator.CreateModel(point, Application.StartupPath + @"\Model\" + modelname, modlescal, TerraExplorerX.ModelTypeCode.MT_ANIMATION, id, "坦克");
            tmodel.Attachment.AttachTo(pdyna.ID, 0, 0, 0);
            img = GlobalObjects.Instance.World3D.Creator.CreateImageLabel(point, Application.StartupPath + @"\Model\" + imgshowname, null, id, "");
            //img.Position.
            img1 = GlobalObjects.Instance.World3D.Creator.CreateImageLabel(point, Application.StartupPath + @"\Model\" + targtename, null, id, "");
            img.Style.Scale = imgscal;
            img1.Style.Scale = imgtargtescal;
            img.Attachment.AttachTo(tmodel.ID, showimgx, showimgy, showimgz);
            GlobalObjects.Instance.World3D.ProjectTree.SetVisibility(img1.TreeItem.ItemID, false);
        }

        public TankClass(TerraExplorerX.IPosition6 point, TerraExplorerX.IPosition6 pointt, double seepd, string modelname, double modlescal, string imgshowname,
            double imgscal, double showimgx, double showimgy, double showimgz, string targtename, double imgtargtescal,Range acrange)
        {
            //this.point = point;
            double x = point.X;
            double y = point.Y;
            int id = GlobalObjects.Instance.World3D.ProjectTree.FindItem("装备");

            double[] vv = new double[] {

                        point.X,  point.Y,  0, 
            
                        pointt.X,  pointt.Y,  0};


            ITerrainDynamicObject6 pdyna = GlobalObjects.Instance.World3D.Creator.CreateDynamicObject(vv, TerraExplorerX.DynamicMotionStyle.MOTION_GROUND_VEHICLE, TerraExplorerX.DynamicObjectType.DYNAMIC_VIRTUAL, "路径", 1, TerraExplorerX.AltitudeTypeCode.ATC_ON_TERRAIN, id, "");
            //IRouteWaypoint6

            pdyna.Waypoints.AddWaypoint(GlobalObjects.Instance.World3D.Creator.CreateRouteWaypoint(acrange.LeftTopPoint.X, acrange.LeftTopPoint.Y, 0, seepd, 90, 0, 0, 0, 0, ""));

            pdyna.Waypoints.AddWaypoint(GlobalObjects.Instance.World3D.Creator.CreateRouteWaypoint(acrange.RightBottom.X, acrange.LeftTopPoint.Y, 0, seepd, 90, 0, 0, 0, 0, ""));
            pdyna.Waypoints.AddWaypoint(GlobalObjects.Instance.World3D.Creator.CreateRouteWaypoint(acrange.RightBottom.X, acrange.RightBottom.Y, 0, seepd, 90, 0, 0, 0, 0, ""));
            pdyna.Waypoints.AddWaypoint(GlobalObjects.Instance.World3D.Creator.CreateRouteWaypoint(acrange.LeftTopPoint.X, acrange.RightBottom.Y, 0, seepd, 90, 0, 0, 0, 0, "")); 

            //for (int i = 0; i < pdyna.Waypoints.Count; i++)
            //{
            //    pdyna.Waypoints.GetWaypoint(i).Speed = seepd;
            //}


            tmodel = GlobalObjects.Instance.World3D.Creator.CreateModel(point, Application.StartupPath + @"\Model\" + modelname, modlescal, TerraExplorerX.ModelTypeCode.MT_ANIMATION, id, "坦克");
            tmodel.Attachment.AttachTo(pdyna.ID, 0, 0, 0);
            img = GlobalObjects.Instance.World3D.Creator.CreateImageLabel(point, Application.StartupPath + @"\Model\" + imgshowname, null, id, "");
            //img.Position. 
           img.Style.Scale = imgscal;
           if (targtename != "线")
           {
               img1 = GlobalObjects.Instance.World3D.Creator.CreateImageLabel(point, Application.StartupPath + @"\Model\" + targtename, null, id, "");
               img1.Style.Scale = imgtargtescal;
           }
           else
           {double[] cVerticesArray = null;

            ILinearRing cRing = null;

            IGeometry cPolygonGeometry = null;

               cVerticesArray = new double[] {pdyna.Position.X,pdyna.Position.Y,pdyna.Position.Altitude,
                   pointt.X,  pointt.Y,  0

                    };

               cRing = GlobalObjects.Instance.World3D.Creator.GeometryCreator.CreateLinearRingGeometry(cVerticesArray);

            cPolygonGeometry = GlobalObjects.Instance.World3D.Creator.GeometryCreator.CreatePolygonGeometry(cRing, null);
            GlobalObjects.Instance.World3D.Creator.CreatePolyline(cPolygonGeometry,255, AltitudeTypeCode.ATC_ON_TERRAIN,id,"联系线");
           }
            img.Attachment.AttachTo(tmodel.ID, showimgx, showimgy, showimgz);
            GlobalObjects.Instance.World3D.ProjectTree.SetVisibility(img1.TreeItem.ItemID, false);
        }
        public override void ObjectFire()
        {
            GlobalObjects.Instance.World3D.ProjectTree.SetVisibility(img.TreeItem.ItemID, true);
        }

        public override void ObjectStop()
        {
            GlobalObjects.Instance.World3D.ProjectTree.SetVisibility(img.TreeItem.ItemID, false);
           // tmodel.ModelType = TerraExplorerX.ModelTypeCode.MT_NORMAL; ;
        }

        public override void ObjectRun()
        {
           //tmodel.ModelType = TerraExplorerX.ModelTypeCode.MT_ANIMATION;
        }

        public void ObjectBack()
        {
        }
        public override void FireTagete(TerraExplorerX.IPosition6 point)
        {
            img1.Position = point;
            GlobalObjects.Instance.World3D.ProjectTree.SetVisibility(img1.TreeItem.ItemID, true);
        }
    }
}
